package rsj.api.product;

import com.rlyy.aibase.utils.base.Box;
import com.rlyy.aibase.utils.base.MapNode;
import common.util.BoxUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import rsj.api.user.BaseLink;
import rsj.api.user.entity.UserAccount;
import rsj.log.ModuleEnum;
import rsj.log.OperationLog;
import rsj.log.OperationTypeEnum;
import rsj.service.ProdCollService;
import rsj.service.user.IUserService;
import rsj.table.DEL_STATUS;
@RestController
public class DoSaveCollProd extends BaseLink {

    private static final ProdCollService prodCollService = ProdCollService.getInstance();

    @Autowired
    private IUserService userService;

    /**
     * Org_Id
     * Prod_Id
     * Coll_Status
     * @param in
     * @return
     */
    @RequestMapping(value = "rsj_prod_collect")
    @OperationLog(description = "收藏产品", logType = OperationTypeEnum.UPDATE, logModule = ModuleEnum.PRODUCT_MANAGEMENT)
    public Box executeLink(Box in){
        MapNode data = in.getMapNode("data");
        MapNode user = in.getMapNode("$user");
        UserAccount userInfo = userService.getUserInfo(user.getValue("User_Id"));
        data.putNode("Org_Id", userInfo.getUserOrgId());
        prodCollService.save(data);

        return BoxUtil.successBox(in, data.getValue("Coll_Status").equals(DEL_STATUS.YES) ? "收藏成功！" : "成功取消收藏！");
    }

}
